package com.github.fastjson;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONReader;
import org.junit.jupiter.api.Test;

/**
 * @author zhangcheng
 * @date 2022/10/25 10:42
 * @description
 */
public class FastJson2Test {

    public static void main(String[] args) {
        String jsonStr = "{\"store\":{\"bicycle\":{\"color\":\"red\",\"price\":19.95},\"book\":[{\"author\":\"刘慈欣\",\"price\":8.95,\"category\":\"科幻\",\"title\":\"三体\"},{\"author\":\"itguang\",\"price\":12.99,\"category\":\"编程语言\",\"title\":\"go语言实战\"}]},\"a_b\":\"123\",\"aC\":\"456\"}";
        StoreEntity jsonObject = JSON.parseObject(jsonStr,StoreEntity.class);
        System.out.println(jsonObject.getaB());
        jsonObject = JSON.parseObject(jsonStr,StoreEntity.class, JSONReader.Feature.SupportSmartMatch);
        System.out.println(jsonObject.getaB());
        System.out.println(jsonObject);
    }


    @Test
    public void test() {
        String json = "{\"@type\":\"com.github.fastjson.MqttMessage\",\"requestId\":\"123\",\"msg\":456}";
        MqttMessage mqttMessage = new MqttMessage();
        mqttMessage.setIsSuccess(true);

        String s = JSON.toJSONString(mqttMessage);

        MqttMessage2 mqttMessage2 = JSON.parseObject(json, MqttMessage2.class,JSONReader.Feature.SupportAutoType);
        System.out.println(s);

    }

    @Test
    public void test1() {
        System.out.println("230403_232922_55HDE5_BH2_1AE5330112N_PC3.csv".matches("^\\d{6}_\\d{6}_[\\w,\\d]{6}_[\\w,\\d]{3}_[\\w,\\d]{11}_[\\w,\\d]{3}.csv$"));
        System.out.println("230403_232922_55HDE5_BH2_1AE5330112N_PC3.csv".endsWith(".csv"));


    }
}
